$.fn.datagrid.defaults.onLoadError = function () {
    $.messager.alert('错误提示', '请确认您访问的地址是否正确，并且是否拥有访问的权限!', 'error');
};

// datagrid 默认属性重写
$.fn.datagrid.defaults.fit = true;
$.fn.datagrid.defaults.fitColumns = true;
$.fn.datagrid.defaults.pagination = true;
$.fn.datagrid.defaults.pageSize = 20;
$.fn.datagrid.defaults.method = 'get';
$.fn.datagrid.defaults.loadFilter = function (data) {
    if ("SUCCESS" == data.state) {
        data.rows = data.data.content;
        data.total = data.data.totalElements;
        return data;
    }
}

$.fn.combobox.defaults.method = 'get';
$.fn.combobox.defaults.valueField = "code";
$.fn.combobox.defaults.textField = "name";
$.fn.combobox.defaults.loadFilter = function (data) {
    if ("SUCCESS" == data.state) {
        console.log(data.data);
        return data.data;
    } else {
        $.messager.alert('提示信息', '数据加载失败', 'info');
    }
}

// {"total":4,"rows":[
// 	{"name":"Name","value":"Bill Smith","group":"ID Settings","editor":"text"},
// 	{"name":"Address","value":"","group":"ID Settings","editor":"text"},
// 	{"name":"SSN","value":"123-456-7890","group":"ID Settings","editor":"text"},
// 	{"name":"Email","value":"bill@gmail.com","group":"Marketing Settings","editor":{
// 		"type":"validatebox",
// 		"options":{
// 			"validType":"email"
// 		}
// 	}}
// ]}


// $.fn.datagrid.defaults.selectOnCheck=false;
$.fn.datagrid.defaults.striped = true;
$.fn.datagrid.defaults.idField = 'id';
$.fn.datagrid.defaults.loadMsg = '数据加载中....';


//treegrid 默认属性重写
$.fn.treegrid.defaults.fit = true;
$.fn.treegrid.defaults.method = 'get';
$.fn.treegrid.defaults.striped = true;
$.fn.treegrid.defaults.singleSelect = true;


//window 默认属性重写
$.fn.window.defaults.title = "操作";
$.fn.window.defaults.closed = true;
$.fn.window.defaults.minimizable = false;
$.fn.window.defaults.collapsible = false;
$.fn.window.defaults.modal = true;
$.fn.window.defaults.width = 800;
$.fn.window.defaults.height = 600;
//  tabs 默认属性重写
$.fn.tabs.defaults.fit = true;

// 表单序列化
$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

String.prototype.formatMoney = function (places, symbol, thousand, decimal) {
    var number = this.toString();
    places = !isNaN(places = Math.abs(places)) ? places : 2;
    symbol = symbol !== undefined ? symbol : "";
    thousand = thousand || ",";
    decimal = decimal || ".";
    var negative = number < 0 ? "-" : "", i = parseInt(number = Math.abs(number || 0).toFixed(places), 10) + "";
    var j = (j = i.length) > 3 ? j % 3 : 0;
    var result = symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
    return result;
}
